<?php
/**
 * 短信消息接口控制器类
 * User: 苏近之
 * Date: 2019-03-23
 * Time: 18:13
 */

namespace app\user\controller;

use app\common\base\ApiController;
use app\common\exception\RequestParamsVerifyFailed;
use app\user\service\SmsService;
use app\user\validator\SmsMessageRegister;
use think\facade\Request;

class SmsMessage extends ApiController
{

    /**
     * 发送注册短信
     * @throws
     */
    public function register()
    {
        $requestParams = Request::get();
        $validator = new SmsMessageRegister();
        if (!$validator->check($requestParams)) {
            throw new RequestParamsVerifyFailed($validator->getError());
        }
        SmsService::setPhone($requestParams['phone'])->register();

        return $this->responseWithJson();
    }

    /**
     * 发送忘记密码短信
     * @throws
     */
    public function forget()
    {
        $requestParams = Request::get();
        $validator = new SmsMessageRegister();
        if (!$validator->check($requestParams)) {
            throw new RequestParamsVerifyFailed($validator->getError());
        }
        SmsService::setPhone($requestParams['phone'])->forget();

        return $this->responseWithJson();
    }

}